//
//  RouteConfig.swift
//  TODOApp
//
//  Created by chenyh on 2018/5/24.
//  Copyright © 2018年 chenyh. All rights reserved.
//

import Foundation
/// 服务器环境:线上、线下、测试
public enum ServerEnv: String {
    case dev = "127.0.0.1:8080/api"
    case test = "0.0.0.0:8080/api"
    case pro = "95.96.95.97:5555/api"
}

/// 集中管理终端模块
///
/// - auth: 有关于账号的 登录、注册、忘记密码、修改密码、等
/// - user: 个人中心模块
/// - home: 首页模块
/// - content: 发布内容模块
public enum ControllerType: String {
    case auth = "/auth"
    case user = "/user"
    case home = "/home"
    case content = "/content"
}
/// 集中管理终端模块子路径
///
/// - register: 注册
/// - login: 登录
public enum ApiRequestList {
    //MARK: Auth模块接口
    case register
    case login
    //MARK: 个人中心模块接口
    //MARK: 首页模块接口
    case todos
    case addTodoItem
    case editTodoItem
    case delTodoItem
    //MARK: 发布模块接口
    public func api() -> String {
        return "/\(self)"
    }
}
/// 路由操作管理
///
/// - login: 登录: 用户名、密码
/// - register: 注册: 用户名、密码
public enum ApiRequestManager {
    case login(username: String,password: String)
    case register(username: String,password: String)
    
    case getTodoList(pageIndex: Int,pageSize: Int)
    case addTodo(title: String,content: String)
    case editTodo(todoId: Int,title: String,content: String)
    case delTodo(todoId: Int)
}
extension ApiRequestManager: Request {
    public var requestModel: RequestConfiguration {
        var model = RequestConfiguration()
        switch self {
        case let .getTodoList(pageIndex,pageSize):
            model.requestAlertText = "请求Todo列表..."
            model.requestConfig = (.home,.todos)
            model.requestIsHUD = true
            model.requestParams = ["pageIndex": pageIndex,"pageSize": pageSize]
            model.requestType = .get
            
        case let .delTodo(todoId):
            model.requestAlertText = "删除单个TodoItem"
            model.requestConfig = (.home,.delTodoItem)
            model.requestIsHUD = true
            model.requestParams = ["todoId": todoId]
            model.requestType = .delete
            
        case let .addTodo(title,content):
            model.requestAlertText = "添加一条TodoItem..."
            model.requestConfig = (.home,.addTodoItem)
            model.requestIsHUD = true
            model.requestParams = ["title": title,"content": content]
            
            
        case let .editTodo(todoId,title,content):
            model.requestAlertText = "编辑一条TodoItem..."
            model.requestConfig = (.home,.editTodoItem)
            model.requestIsHUD = true
            model.requestParams = ["todoId": todoId,"title": title,"content": content]
            
        case let .login(username,password):
            model.requestAlertText = "登录中..."
            model.requestConfig = (.auth,.login)
            model.requestIsHUD = true
            model.requestParams = ["username": username,"password": password]
            
        case let .register(username,password):
            model.requestAlertText = "注册中..."
            model.requestConfig = (.auth,.register)
            model.requestIsHUD = true
            model.requestParams = ["username": username,"password": password]
        }
        return model
    }
}

